﻿#region Using directives

using System;
using NetROS.Tiers.Entities.Validation;
using System.ComponentModel;

#endregion

namespace NetROS.Tiers.Entities
{
    ///<summary>
    ///</summary>
    [Serializable]
    [CLSCompliant(true)]
    public class Racun : Dokument
    {
        ///<summary>
        ///</summary>
        public Racun():base()
        {
        
        }
          ///<summary>
          ///</summary>
          [DescriptionAttribute(""), Bindable(BindableSupport.Yes)]
       [DataObjectField(false, false, true, 300)]
       public Int32? DanaDoStogod
       {
           get
           {
               TimeSpan? tmp;
               tmp = base.DatumDo - base.Datum;
               
                   return tmp.Value.Days;

              }

           set
              {
                  if (value.HasValue)
                  {
                      base.DatumDo = base.Datum.AddDays(Convert.ToDouble(value.Value));
                  }
                  else
                  {
                      base.DatumDo = null;
                  }
           }
       } 

            
    }
    

	///<summary>
	/// An object representation of the 'tblDokument' table. [No description found the database]	
	///</summary>
	/// <remarks>
	/// This file is generated once and will never be overwritten.
	/// </remarks>	
	[Serializable]
	[CLSCompliant(true)]
	public partial class Dokument : DokumentBase
	{		
		#region Constructors

		///<summary>
		/// Creates a new <see cref="Dokument"/> instance.
		///</summary>
		public Dokument():base(){}	
		
		#endregion


        /// <summary>
        /// Assigns validation rules to this object based on model definition.
        /// </summary>
        /// <remarks>This method overrides the base class to add schema related validation.</remarks>
        protected override void AddValidationRules()
        {
           base.AddValidationRules();

           ValidationRules.AddRule(ValidateDokumentStavkaCollection, new ValidationRuleArgs("DokumentStavkaCollection"));

       }

       /// <summary>
       /// 	Gets or sets the DanaDoValute property. 
       ///		
       /// </summary>
       /// <value>This type is Int32.</value>
       /// <remarks>
       /// This property can be set to null. 
       /// </remarks>
       
        [DescriptionAttribute(""), Bindable(BindableSupport.Yes)]
       [DataObjectField(false, false, true, 300)]
       public Int32? DanaDoValute
       {
           get
           {
               TimeSpan? tmp;
               tmp = base.DatumDo - base.Datum;
               if (tmp != null && tmp.HasValue)
                   return tmp.Value.Days;
               return null;

              }

           set
              {
                  if (value.HasValue)
                  {
                      base.DatumDo = base.Datum.AddDays(Convert.ToDouble(value.Value));
                  }
                  else
                  {
                      base.DatumDo = null;
                  }
           }
       } 

       private bool ValidateDokumentStavkaCollection(object target, ValidationRuleArgs e)
       {

           foreach (DokumentStavka tmp in DokumentStavkaCollection)
           {
               tmp.Validate();
           }
           if (!DokumentStavkaCollection.IsValid)
           {

               e.Description = "Greska Nevaljajuci.";

               return false;

           }

           return true;

       }

	}

}
